﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using GalaSoft.MvvmLight;
using Model;
using RestSharp;

namespace UI.ViewModel
{
    [PropertyChanged.AddINotifyPropertyChangedInterface]
   public class ChaobiaoViewModel
    {

        public string MeterType { get; set; }


        public Model.F_Water CurrWater { get; set; }


        public List<F_Water> ListWater { get; set; }
       // public List<F_Water> ListElec { get; set; }
       // public List<F_Water> ListQi { get; set; }
        public List<Building> ListBuilds { get; set; }
        public List<Rooms> ListRooms { get; set; }
        public List<int> ListLayers { get; set; }
        public int SelectLayer { get; set; }
         
        public Building SelectedBuild { get; set; }
       public  HandyControl.Controls.Dialog Dialog { get; set; }



        public void LoadWater(string type)
        {

           //var client = new RestSharp.RestClient(new Uri(Comm.TempData.BaseUrl));
           // var res = new RestRequest("water", Method.GET);
           // var rsp = client.Get<ListDataResponse<Model.F_Water>>(res);
            var context = new Model.DataContext();
            var list  = context.DB.Queryable<Model.F_Water>().Where(w => w.MeterType == type).ToList();

            ListWater = list;
            switch (type)
            {
                case "水费":
                    ListWater = list ;
                    break;
                case "电费":
                  //  ListElec = list;
                    break;
                case "天然气":
                   // ListQi = list;
                    break;
            }
         


        }

        public void Query(string buildId, string roomNo, string ownerName)
        {

            var dbContext = new Model.DataContext();
            //先查询RoomID
            var query = dbContext.DB.Queryable<Model.F_Water>();


            if (!string.IsNullOrEmpty(buildId))
            {
                query = query.Where(r => r.BuildId.ToString() == buildId);
            }

            if (!string.IsNullOrEmpty(roomNo))
            {
                query = query.Where(r => r.RoomNo.Contains(roomNo));
            }

            if (!string.IsNullOrEmpty(ownerName))
            {
                query = query.Where(r => r.Owner.Contains(ownerName));
            }

            ListWater = query.Where(w => w.MeterType == MeterType).ToList();


        }
    }
}
